import { useState, useEffect } from 'react'

function usePosition () {
  const [position, setPosition] = useState({ x: 0, y: 0 })

  const move = e => {
    setPosition({
      x: e.clientX,
      y: e.clientY
    })
  }

  useEffect(() => {
    window.addEventListener('mousemove', move)

    return () => {
      window.removeEventListener('mousemove', move)
    }
  }, [])

  return [position]
}

export { usePosition }
